package com.readaloud.wicket;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.PropertyModel;

import com.arjuna.ats.internal.jdbc.drivers.modifiers.list;
import com.readaloud.constants.Constants;
import com.readaloud.hibernate.user.Books;
import com.readaloud.hibernate.user.GenreListBean;


public class BookClubListPanel extends Panel {

	public BookClubListPanel(String id) {
		super(id);
		
		
		IModel<List<GenreListBean>> model = new LoadableDetachableModel() {
            protected Object load() {
                return getGenreList();
            }
        };
        
        setDefaultModel(model);
		ListView genreListView = new ListView("genreList", getDefaultModel()){
			@Override
			protected void populateItem(ListItem item) {
                Link view = new Link("genre", item.getModel()) {
                    public void onClick() {
                        setResponsePage(new BookClubPanel((GenreListBean)getModelObject()));
                    }
                };
                view.add(new Label("genreName",
                        new PropertyModel(item.getModel(), "genreName")));
                item.add(view);
			}
		};
		add(genreListView);

	}
	
	public List<GenreListBean> getGenreList(){
		List<GenreListBean> list = new ArrayList<GenreListBean>();
		for(String genreName: Constants.GENRE ){
			GenreListBean genreListBean = new GenreListBean(genreName);
			list.add(genreListBean);
		}
		return list;
	}
	
}
